package com.smile.controller;

import cn.hutool.core.bean.BeanUtil;
import com.smile.commons.page.R;
import com.smile.model.dto.request.SpeakerAudioPlayStartRequestDTO;
import com.smile.model.dto.request.SpeakerPlayModeSetRequestDTO;
import com.smile.model.dto.request.SpeakerPlayVolumeSetRequestDTO;
import com.smile.model.dto.request.SpeakerTtsPlayStartRequestDTO;
import com.smile.model.request.SpeakerAudioPlayStartRequest;
import com.smile.model.request.SpeakerPlayModeSetRequest;
import com.smile.model.request.SpeakerPlayVolumeSetRequest;
import com.smile.model.request.SpeakerTtsPlayStartRequest;
import com.smile.service.SpeakerService;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/speaker")
public class SpeakerController {

    @Autowired
    private SpeakerService speakerService;

    @PostMapping("/speakerPlayVolumeSet")
    public R<Void> speakerPlayVolumeSet(@RequestBody SpeakerPlayVolumeSetRequest speakerPlayVolumeSetRequest) throws MqttException {
        SpeakerPlayVolumeSetRequestDTO speakerPlayVolumeSetRequestDTO = BeanUtil.copyProperties(speakerPlayVolumeSetRequest, SpeakerPlayVolumeSetRequestDTO.class);
        speakerService.speakerPlayVolumeSet(speakerPlayVolumeSetRequestDTO);
        return R.ok();
    }

    @PostMapping("/speakerPlayModeSet")
    public R<Void> speakerPlayModeSet(@RequestBody SpeakerPlayModeSetRequest speakerPlayModeSetRequest) throws MqttException {
        SpeakerPlayModeSetRequestDTO speakerPlayModeSetRequestDTO = BeanUtil.copyProperties(speakerPlayModeSetRequest, SpeakerPlayModeSetRequestDTO.class);
        speakerService.speakerPlayModeSet(speakerPlayModeSetRequestDTO);
        return R.ok();
    }

    @PostMapping("/speakerTtsPlayStart")
    public R<Void> speakerTtsPlayStart(@RequestBody SpeakerTtsPlayStartRequest speakerTtsPlayStartRequest) throws MqttException {
        SpeakerTtsPlayStartRequestDTO speakerTtsPlayStartRequestDTO = BeanUtil.copyProperties(speakerTtsPlayStartRequest, SpeakerTtsPlayStartRequestDTO.class);
        speakerService.speakerTtsPlayStart(speakerTtsPlayStartRequestDTO);
        return R.ok();
    }

    @PostMapping("/speakerAudioPlayStart")
    public R<Void> speakerAudioPlayStartRequest(@RequestBody SpeakerAudioPlayStartRequest speakerAudioPlayStartRequest) throws MqttException {
        speakerService.speakerAudioPlayStartRequest(BeanUtil.copyProperties(speakerAudioPlayStartRequest, SpeakerAudioPlayStartRequestDTO.class));
        return R.ok();
    }


}
